package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_DuiJie_XuQiuActivity;
import com.example.xianji.activity.Main_My_Receive_DetailActivity;
import com.example.xianji.R;
import com.example.xianji.bean.My_DuiJie;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DuiJie_Adapter extends BaseAdapter {
private Context mContext;
private ArrayList<My_DuiJie> duijie_list;
private int my_duijie;
private int from;


	

	

	public DuiJie_Adapter(Context mContext, ArrayList<My_DuiJie> duijie_list,
		int my_duijie, int from) {
	super();
	this.mContext = mContext;
	this.duijie_list = duijie_list;
	this.my_duijie = my_duijie;
	this.from = from;
}

	@Override
	public int getCount() {
		return duijie_list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder mHolder;
		if(convertView==null){
			
			mHolder=new Holder();
			
			convertView=View.inflate(mContext,R.layout.my_duijie_listview_item,null);
			mHolder.textview_duijie_time=(TextView) convertView.findViewById(R.id.textview_duijie_time);
			mHolder.duijie_title=(TextView) convertView.findViewById(R.id.duijie_title);
			mHolder.duijie_fabu=(TextView) convertView.findViewById(R.id.duijie_fabu);
			
			
			convertView.setTag(mHolder);
			
		}
		
		mHolder=(Holder) convertView.getTag();
		mHolder.textview_duijie_time.setText(duijie_list.get(position).getCreated_at());
		
		Log.i("time time time time",duijie_list.get(position).getCreated_at());
		
		mHolder.duijie_title.setText(duijie_list.get(position).getTitle());
		if(from==1){
		if(duijie_list.get(position).getStatus()==1){
			mHolder.duijie_fabu.setText("已发布");
		}else if(duijie_list.get(position).getStatus()==11){
			mHolder.duijie_fabu.setText("待审核");
			
		}else if(duijie_list.get(position).getStatus()==10){
			mHolder.duijie_fabu.setText("审核不通过");
			
		}else if(duijie_list.get(position).getStatus()==12||duijie_list.get(position).getStatus()==16||duijie_list.get(position).getStatus()==17){
			mHolder.duijie_fabu.setText("已发布");
			
		}else if(duijie_list.get(position).getStatus()==13||duijie_list.get(position).getStatus()==14){
			mHolder.duijie_fabu.setText("已发布");
			
		}else if(duijie_list.get(position).getStatus()==15){
			mHolder.duijie_fabu.setText("分类不确定");
			
		}else if(duijie_list.get(position).getStatus()==2){
			mHolder.duijie_fabu.setText("对接中");
			
		}else if(duijie_list.get(position).getStatus()==3||duijie_list.get(position).getStatus()==31||duijie_list.get(position).getStatus()==32||duijie_list.get(position).getStatus()==4||duijie_list.get(position).getStatus()==41||
				duijie_list.get(position).getStatus()==5||duijie_list.get(position).getStatus()==6){
			mHolder.duijie_fabu.setText("已完结");
			
		}else if(duijie_list.get(position).getStatus()==7||duijie_list.get(position).getStatus()==71||duijie_list.get(position).getStatus()==72){
			mHolder.duijie_fabu.setText("结束");
			
		}else if(duijie_list.get(position).getStatus()==8){
			mHolder.duijie_fabu.setText("项目暂停");
			
		}
		}
		else if(from==2){
			if(duijie_list.get(position).getStatus()==1){
				mHolder.duijie_fabu.setText("未阅读");
		}else if(duijie_list.get(position).getStatus()==2){
			
			mHolder.duijie_fabu.setText("已阅读");
		}
		}
		final int a=position;
		
		convertView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(from==1){
				Intent intent=new Intent(mContext, Main_DuiJie_XuQiuActivity.class);
				intent.putExtra("demand_id", duijie_list.get(a).getDemand_id());
				/**
				 * 隐藏列表传的是2
				 */
				intent.putExtra("duijie_details", my_duijie);
				mContext.startActivity(intent);
				}else{
					Intent intent=new Intent(mContext,Main_My_Receive_DetailActivity.class);
					intent.putExtra("receive_id", duijie_list.get(a).getId());
					mContext.startActivity(intent);
					
				}
			}
		});
		
		return convertView;
	}
class Holder{
	TextView textview_duijie_time;
	TextView duijie_title;
	TextView duijie_fabu;
}

}
